/*
 * @描述:
 * @作者: 约訂
 * @Date: 2024-11-08 14:30:25
 * @LastEditTime: 2024-11-08 14:35:39
 * @修改人员: 约訂
 */
import { nextTick, createApp, h } from "vue";
import RightClickMenu from "../pages/chat/chatIndex/indexSub/rightClickMenu.vue";

export default {
  mounted(el, binding) {
    const menus = binding.value;
    const menuComponent = {
      data() {
        return {
          menus,
        };
      },
      methods: {
        onSelect(item) {
          if (item.callback) {
            item.callback();
          }
        },
      },
      render() {
        return h(RightClickMenu, {
          menus: this.menus,
          onSelect: this.onSelect,
        });
      },
    };

    const vm = createApp(menuComponent).mount(document.createElement("div"));
    document.body.appendChild(vm.$el);

    el.addEventListener("contextmenu", (event) => {
      event.preventDefault();
      vm.$el.style.top = `${event.clientY}px`;
      vm.$el.style.left = `${event.clientX}px`;
      vm.$el.style.display = "block";
    });

    window.addEventListener("click", () => {
      vm.$el.style.display = "none";
    });
  },
};
